<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><title>Web APIs第六天 | XC's Blog</title><meta name="keywords" content="Web APIs笔记"><meta name="author" content="XC's Blog"><meta name="copyright" content="XC's Blog"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="BOM- 操作浏览器1. JS执行机制 JavaScript 语言的一大特点就是单线程，也就是说，同一个时间只能做一件事。这是因为 Javascript 这 门脚本语言诞生的使命所致——JavaScript 是为处理页面中用户的交互，以及操作 DOM 而诞生的。比 如我们对某个 DOM 元素进行添加和删除操作，不能同时进行。 应该先进行添加，之后再删除 单线程就意味着，所有任务需要排队，前一个任务"><meta property="og:type" content="article"><meta property="og:title" content="Web APIs第六天"><meta property="og:url" content="https://webxc.eu.org/post/fr67/index.html"><meta property="og:site_name" content="XC&#39;s Blog"><meta property="og:description" content="BOM- 操作浏览器1. JS执行机制 JavaScript 语言的一大特点就是单线程，也就是说，同一个时间只能做一件事。这是因为 Javascript 这 门脚本语言诞生的使命所致——JavaScript 是为处理页面中用户的交互，以及操作 DOM 而诞生的。比 如我们对某个 DOM 元素进行添加和删除操作，不能同时进行。 应该先进行添加，之后再删除 单线程就意味着，所有任务需要排队，前一个任务"><meta property="og:locale" content="zh_CN"><meta property="og:image" content="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/webapis.jpg"><meta property="article:published_time" content="2023-04-11T20:30:00.000Z"><meta property="article:modified_time" content="2023-08-30T18:00:49.041Z"><meta property="article:author" content="XC&#39;s Blog"><meta property="article:tag" content="Web APIs笔记"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/webapis.jpg"><link rel="shortcut icon" href="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><link rel="canonical" href="https://webxc.eu.org/post/fr67/"><link rel="preconnect" href="//cdn.jsdelivr.net"><link rel="preconnect" href="//busuanzi.ibruce.info"><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://npm.elemecdn.com/@fortawesome/fontawesome-free@6.2.0/css/all.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/node-snackbar/dist/snackbar.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/@fancyapps/ui/dist/fancybox.css" media="print" onload='this.media="all"'><script>const GLOBAL_CONFIG={root:"/",algolia:void 0,localSearch:{path:"/search.xml",preload:!1,languages:{hits_empty:"找不到您查询的内容：${query}"}},translate:void 0,noticeOutdate:void 0,highlight:{plugin:"highlighjs",highlightCopy:!0,highlightLang:!0,highlightHeightLimit:!1},copy:{success:"吾辈宣布,你的剪切板已被占领",error:"呀~复制失败,请在尝试下",noSupport:"对不起,你的浏览器不支持"},relativeDate:{homepage:!1,post:!1},runtime:"",date_suffix:{just:"刚刚",min:"分钟前",hour:"小时前",day:"天前",month:"个月前"},copyright:{limitCount:60,languages:{author:"作者: XC's Blog",link:"链接: ",source:"来源: XC's Blog",info:"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},lightbox:"fancybox",Snackbar:{chs_to_cht:"您已切换为繁体",cht_to_chs:"您已切换为简体",day_to_night:"您已切换为深色主题",night_to_day:"您已切换为浅色主题",bgLight:"#3b70fc",bgDark:"#121212",position:"bottom-center"},source:{justifiedGallery:{js:"https://npm.elemecdn.com/flickr-justified-gallery/dist/fjGallery.min.js",css:"https://npm.elemecdn.com/flickr-justified-gallery/dist/fjGallery.css"}},isPhotoFigcaption:!1,islazyload:!0,isAnchor:!0}</script><script id="config-diff">var GLOBAL_CONFIG_SITE={title:"Web APIs第六天",isPost:!0,isHome:!1,isHighlightShrink:!1,isToc:!0,postUpdate:"2023-08-30 18:00:49"}</script><noscript><style>#nav{opacity:1}.justified-gallery img{opacity:1}#post-meta time,#recent-posts time{display:inline!important}</style></noscript><script>(e=>{e.saveToLocal={set:function(e,t,o){if(0===o)return;const n=864e5*o,a={value:t,expiry:(new Date).getTime()+n};localStorage.setItem(e,JSON.stringify(a))},get:function(e){const t=localStorage.getItem(e);if(!t)return;const o=JSON.parse(t);if(!((new Date).getTime()>o.expiry))return o.value;localStorage.removeItem(e)}},e.getScript=e=>new Promise(((t,o)=>{const n=document.createElement("script");n.src=e,n.async=!0,n.onerror=o,n.onload=n.onreadystatechange=function(){const e=this.readyState;e&&"loaded"!==e&&"complete"!==e||(n.onload=n.onreadystatechange=null,t())},document.head.appendChild(n)})),e.activateDarkMode=function(){document.documentElement.setAttribute("data-theme","dark"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#0d0d0d")},e.activateLightMode=function(){document.documentElement.setAttribute("data-theme","light"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#ffffff")};const t=saveToLocal.get("theme");"dark"===t?activateDarkMode():"light"===t&&activateLightMode();const o=saveToLocal.get("aside-status");void 0!==o&&("hide"===o?document.documentElement.classList.add("hide-aside"):document.documentElement.classList.remove("hide-aside"));/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)&&document.documentElement.classList.add("apple")})(window)</script><link rel="stylesheet" href="https://cdn1.tianli0.top/gh/web-xc/My-blog-CSS/mgi.css"><link rel="stylesheet" href="https://cdn1.tianli0.top/gh/web-xc/My-blog-CSS/mg111.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.16/css/mg2.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.11/css/styless.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.11/css/styles.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.11/css/font.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.15/css/font2.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiper.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiperstyle.css" media="print" onload='this.media="all"'><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg" onerror='onerror=null,src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="avatar"></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">95</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">25</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><hr><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw iconfont icon-shouye"></i> <span>首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw iconfont icon-shijian"></i> <span>时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw iconfont icon-biaoqian"></i> <span>标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw iconfont icon-fenlei"></i> <span>分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw iconfont icon-lianxiwomen"></i> <span>友联</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw iconfont icon-iconzhengli-"></i> <span>关于</span></a></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw iconfont icon-a-wangzhanchaojilianjiehulianwang"></i> <span>推荐</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="http://www.inode.club/"><i class="fa-fw fa-sharp fa-solid fa-square-rss"></i> <span>程序员指南</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="http://ife.baidu.com/"><i class="fa-fw fa-brands fa-vuejs"></i> <span>前端技术学园</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.yuque.com/tademanong/ag7q4n"><i class="fa-fw fa-solid fa-users"></i> <span>前端技术圈</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.code-nav.cn/"><i class="fa-fw fa-solid fa-shop"></i> <span>编程导航</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://q.shanyue.tech/"><i class="fa-fw fa-brands fa-square-js"></i> <span>每日一题</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://fanyouf.gitee.io/u1word/#/h5"><i class="fa-fw fa-solid fa-headphones"></i> <span>前端必会单词</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://site.51git.cn/render/gonav/4.html"><i class="fa-fw iconfont icon-wangzhandingzhi"></i> <span>网址导航</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.webxc.eu.org/music/"><i class="fa-fw iconfont icon-musical-note"></i> <span>音乐解锁</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image:url('https://cdn1.tianli0.top/gh/web-xc/iMG/postss/webapis.jpg')"><nav id="nav"><span id="blog_name"><div class="back-home-button" tabindex="-1"><i class="back-home-button-icon fas fa-grip-vertical"></i><div class="back-menu-list-groups"><div class="back-menu-list-group"><div class="back-menu-list-title">项目</div><div class="back-menu-list"><a class="back-menu-item" href="/" title="前往博客主页" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">主站</span></a><a class="back-menu-item" href="https://e.webxc.eu.org/" rel="external nofollow" title="前往学习笔记" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">学习笔记</span></a><a class="back-menu-item" href="https://v.webxc.eu.org/" rel="external nofollow" title="VuePress学习文档" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">VuePress文档</span></a><a class="back-menu-item" href="https://b.webxc.eu.org/" rel="external nofollow" title="旧站Hexo" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">旧站Hexo</span></a><a class="back-menu-item" href="https://gridea.webxc.eu.org/" rel="external nofollow" title="Gridea笔记" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Gridea笔记</span></a><a class="back-menu-item" href="https://c.webxc.eu.org/" rel="external nofollow" title="魔改Hexo" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">魔改Hexo</span></a></div></div><div class="back-menu-list-group"><div class="back-menu-list-title">博客镜像</div><div class="back-menu-list"><a class="back-menu-item" href="https://blog.webxc.eu.org/" title="Vercel镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Vercel镜像</span></a><a class="back-menu-item" href="https://webxc.tk/" title="Netlify镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Netlify镜像</span></a><a class="back-menu-item" href="https://web-xc.gitee.io/" title="Gitee镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Gitee镜像</span></a><a class="back-menu-item" href="https://cf.webxc.eu.org/" title="Cloudflare镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Cloudflare镜像</span></a><a class="back-menu-item" href="https://render.webxc.eu.org/" title="Render镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Render镜像</span></a></div></div></div></div><a id="site-name" href="/"><div class="title">XC's Blog</div><i class="fa-solid fa-house"></i></a></span><div class="mask-name-container"><center id="name-container"><a id="page-name" href="javascript:btf.scrollToDest(0, 500)">PAGE_NAME</a></center></div><div id="menus"><div class="nav-button" id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i> <span>搜索</span></a></div><div class="nav-button" id="darkmode_navswitch"><a class="darkmode_switchbutton" type="button" title="浅色和深色模式转换" onclick="switchDarkMode()"><i class="fas fa-adjust"></i></a></div><div class="nav-button" id="nav-totop"><a class="totopbtn"><i class="fas fa-arrow-up"></i><span id="percent" onclick="btf.scrollToDest(0,500)">0</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw iconfont icon-shouye"></i> <span>首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw iconfont icon-shijian"></i> <span>时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw iconfont icon-biaoqian"></i> <span>标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw iconfont icon-fenlei"></i> <span>分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw iconfont icon-lianxiwomen"></i> <span>友联</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw iconfont icon-iconzhengli-"></i> <span>关于</span></a></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw iconfont icon-a-wangzhanchaojilianjiehulianwang"></i> <span>推荐</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="http://www.inode.club/"><i class="fa-fw fa-sharp fa-solid fa-square-rss"></i> <span>程序员指南</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="http://ife.baidu.com/"><i class="fa-fw fa-brands fa-vuejs"></i> <span>前端技术学园</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.yuque.com/tademanong/ag7q4n"><i class="fa-fw fa-solid fa-users"></i> <span>前端技术圈</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.code-nav.cn/"><i class="fa-fw fa-solid fa-shop"></i> <span>编程导航</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://q.shanyue.tech/"><i class="fa-fw fa-brands fa-square-js"></i> <span>每日一题</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://fanyouf.gitee.io/u1word/#/h5"><i class="fa-fw fa-solid fa-headphones"></i> <span>前端必会单词</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://site.51git.cn/render/gonav/4.html"><i class="fa-fw iconfont icon-wangzhandingzhi"></i> <span>网址导航</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.webxc.eu.org/music/"><i class="fa-fw iconfont icon-musical-note"></i> <span>音乐解锁</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Web APIs第六天</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-04-11T20:30:00.000Z" title="发表于 2023-04-11 20:30:00">2023-04-11</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-08-30T18:00:49.041Z" title="更新于 2023-08-30 18:00:49">2023-08-30</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Web-APIs%E7%AC%94%E8%AE%B0/">Web APIs笔记</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span data-flag-title="Web APIs第六天"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="twikoo_visitors"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h3 id="BOM-操作浏览器"><a href="#BOM-操作浏览器" class="headerlink" title="BOM- 操作浏览器"></a>BOM- 操作浏览器</h3><h2 id="1-JS执行机制"><a href="#1-JS执行机制" class="headerlink" title="1. JS执行机制"></a>1. JS执行机制</h2><ol><li>JavaScript 语言的一大特点就是单线程，也就是说，同一个时间只能做一件事。这是因为 Javascript 这 门脚本语言诞生的使命所致——JavaScript 是为处理页面中用户的交互，以及操作 DOM 而诞生的。比 如我们对某个 DOM 元素进行添加和删除操作，不能同时进行。 应该先进行添加，之后再删除</li><li>单线程就意味着，所有任务需要排队，前一个任务结束，才会执行后一个任务。这样所导致的问 题是： 如果 JS 执行的时间过长，这样就会造成页面的渲染不连贯，导致页面渲染加载阻塞的感觉</li><li>为了解决这个问题，利用多核 CPU 的计算能力，HTML5 提出 Web Worker 标准，允许 JavaScript 脚本创建多个线程。于是，JS 中出现了同步和异步</li></ol><h3 id="1-同步"><a href="#1-同步" class="headerlink" title="1. 同步"></a>1. 同步</h3><ol><li>前一个任务结束后再执行后一个任务，程序的执行顺序与任务的排列顺序是一致的、同步的。比如做饭的同步 做法：我们要烧水煮饭，等水开了（10分钟之后），再去切菜，炒菜</li><li>同步任务都在主线程上执行，形成一个执行栈</li></ol><h3 id="2-异步"><a href="#2-异步" class="headerlink" title="2. 异步"></a>2. 异步</h3><ol><li>你在做一件事情时，因为这件事情会花费很长时间，在做这件事的同时，你还可以去处理其他事 情。比如做饭的异步做法，我们在烧水的同时，利用这10分钟，去切菜，炒菜</li><li>JS 的异步是通过回调函数实现的</li></ol><h5 id="一般而言，异步任务有以下三种类型"><a href="#一般而言，异步任务有以下三种类型" class="headerlink" title="一般而言，异步任务有以下三种类型:"></a>一般而言，异步任务有以下三种类型:</h5><ol><li>普通事件, 如 click、resize 等</li><li>资源加载, 如 load、error 等</li><li>定时器, 包括 setInterval、setTimeout 等 异步任务相关添加到任务队列中(任务队列也称为消息队列)</li><li>他们的本质区别： 这条流水线上各个流程的执行顺序不同</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 1. JS执行机制 同步 异步</span></span><br><span class="line"><span class="comment">// 同步: 执行栈 在主线程上执行</span></span><br><span class="line"><span class="comment">// 异步: 任务/消息队列 通过回调函数实现</span></span><br><span class="line"><span class="comment">// 1. 先执行栈的同步任务</span></span><br><span class="line"><span class="comment">// 2. 异步任务放入任务队列中</span></span><br><span class="line"><span class="comment">// 3. 同步任务执行完 系统按次序读取异步任务 进入执行栈执行</span></span><br><span class="line"><span class="comment">// 主线程重复获得任务、执行任务、再获取任务、再执行 这种机制称事件循环event loop</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">1</span>)</span><br><span class="line"><span class="built_in">setTimeout</span>(<span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">2</span>)</span><br><span class="line">&#125;, <span class="number">0</span>)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">3</span>)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">11</span>)</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">44</span>)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">22</span>)</span><br><span class="line"><span class="built_in">setTimeout</span>(<span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">33</span>)</span><br><span class="line">&#125;, <span class="number">2000</span>)</span><br></pre></td></tr></table></figure><img src="" data-lazy-src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/js执行机制.jpg" style="zoom:25%"><h2 id="2-JS执行过程"><a href="#2-JS执行过程" class="headerlink" title="2. JS执行过程"></a>2. JS执行过程</h2><ol><li>先执行执行栈中的同步任务</li><li>异步任务放入任务队列中</li><li>一旦执行栈中的所有同步任务执行完毕, 系统就会按次序读取任务队列中的异步任务，于是被读取的异步任务 结束等待状态，进入执行栈，开始执行</li></ol><img src="" data-lazy-src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/js执行机制过程.jpg" style="zoom:33%"> <img src="" data-lazy-src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/js执行机制图解.jpg" style="zoom:33%"><blockquote><p>由于主线程不断的重复获得任务、执行任务、再获取任务、再执行，所以这种机制被称为事件循环event loop</p></blockquote><h2 id="3-Window对象"><a href="#3-Window对象" class="headerlink" title="3. Window对象"></a>3. Window对象</h2><ol><li>BOM(Browser Object Model ) 是浏览器对象模型</li><li>window 是浏览器内置中的全局对象，我们所学习的所有 Web APIs 的知识内容都是基于 window 对象实现的window 对象下包含了 navigator、location、document、history、screen 5个属性, 即所谓的 BOM(浏览器对象模 型)</li><li>document 是实现 DOM 的基础，它其实是依附于 window 的属性</li><li>注：依附于 window 对象的所有属性和方法，使用时可以省略 window</li></ol><img src="" data-lazy-src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/bom对象.jpg" style="zoom:33%"><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// window是最大的对象 浏览器对象模型</span></span><br><span class="line"><span class="comment">// document是DOM最大对象</span></span><br><span class="line"><span class="variable language_">window</span>.<span class="property">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.box&#x27;</span>)</span><br><span class="line"><span class="variable language_">window</span>.<span class="built_in">setInterval</span>()</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">fn</span>(<span class="params"></span>) &#123;</span><br><span class="line"> <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">1</span>)   </span><br><span class="line">&#125;</span><br><span class="line"><span class="variable language_">window</span>.<span class="title function_">fn</span>()</span><br><span class="line"><span class="title function_">addEventListener</span>(<span class="string">&#x27;scroll&#x27;</span>, <span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">2</span>)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="variable language_">window</span>.<span class="title function_">alert</span>()</span><br><span class="line"><span class="variable language_">window</span>.<span class="title function_">prompt</span>()</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="variable language_">window</span>)</span><br></pre></td></tr></table></figure><h3 id="1-定时器-延时函数"><a href="#1-定时器-延时函数" class="headerlink" title="1. 定时器-延时函数"></a>1. 定时器-延时函数</h3><ol><li>JavaScript 内置的一个用来让代码延迟执行的函数，叫 setTimeout</li><li>setTimeout 仅仅只执行一次，所以可以理解为就是把一段代码延迟执行, 平时省略window</li><li>结合递归函数可以使用 setTimeout 实现 setInterval 一样的功能</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 1. 延迟对象 仅执行一次 就没了</span></span><br><span class="line"><span class="keyword">let</span> time = <span class="built_in">setTimeout</span>(<span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">&#x27;爆炸了&#x27;</span>)</span><br><span class="line">&#125;, <span class="number">10000</span>)</span><br><span class="line"><span class="comment">// 2. 清除延迟函数 点击按钮后清除</span></span><br><span class="line"><span class="keyword">let</span> num1 = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;button&#x27;</span>)</span><br><span class="line">num1.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">    <span class="built_in">clearTimeout</span>(time)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure><h5 id="1-两种定时器对比"><a href="#1-两种定时器对比" class="headerlink" title="1. 两种定时器对比:"></a>1. 两种定时器对比:</h5><ol><li>setInterval 的特征是重复执行，首次执行会延时</li><li>setTimeout 的特征是延时执行，只执行 1 次</li><li>setTimeout 结合递归函数，能模拟 setInterval 重复执行</li><li>clearTimeout 清除由 setTimeout 创建的定时任务</li></ol><h5 id="2-5秒钟之后消失的广告"><a href="#2-5秒钟之后消失的广告" class="headerlink" title="2. 5秒钟之后消失的广告"></a>2. 5秒钟之后消失的广告</h5><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 2秒后自动消失广告</span></span><br><span class="line"><span class="keyword">let</span> num2 = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;img&#x27;</span>)</span><br><span class="line"><span class="built_in">setTimeout</span>(<span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">    num2.<span class="property">style</span>.<span class="property">display</span> = <span class="string">&#x27;none&#x27;</span></span><br><span class="line">&#125;, <span class="number">2000</span>)</span><br><span class="line"><span class="comment">// 4. 递归函数: 自己调用自己</span></span><br><span class="line"><span class="comment">// 容易死递归 要加上退出条件</span></span><br><span class="line"><span class="keyword">let</span> num3 = <span class="number">0</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">fn</span>(<span class="params"></span>) &#123;</span><br><span class="line">    num3++</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">1</span>)</span><br><span class="line">    <span class="comment">// 如果要退出 得加上判断条件</span></span><br><span class="line">    <span class="keyword">if</span> (num3 &gt;= <span class="number">10</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 自己调自己</span></span><br><span class="line">    <span class="title function_">fn</span>()</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">fn</span>()</span><br><span class="line"><span class="comment">// 5. 利用递归实现/模拟 setInterval</span></span><br><span class="line"><span class="keyword">let</span> num4 = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;div&#x27;</span>)</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">fn1</span>(<span class="params"></span>) &#123;</span><br><span class="line">    num4.<span class="property">innerHTML</span> = <span class="keyword">new</span> <span class="title class_">Date</span>().<span class="title function_">toLocaleString</span>()</span><br><span class="line">    <span class="built_in">setTimeout</span>(fn1)</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">fn1</span>()</span><br><span class="line"><span class="comment">// 6. 两个定时器对比</span></span><br><span class="line"><span class="comment">// 间歇函数 重复执行 首次延迟执行</span></span><br><span class="line"><span class="comment">// 延迟函数 只执行1次</span></span><br></pre></td></tr></table></figure><h3 id="2-location对象"><a href="#2-location对象" class="headerlink" title="2.  location对象"></a>2. location对象</h3><ol><li>location 的数据类型是对象，它拆分并保存了 URL 地址的各个组成部分</li></ol><h3 id="1-href-属性获取完整的-URL-地址，对其赋值时用于地址的跳转"><a href="#1-href-属性获取完整的-URL-地址，对其赋值时用于地址的跳转" class="headerlink" title="1. href 属性获取完整的 URL 地址，对其赋值时用于地址的跳转"></a>1. href 属性获取完整的 URL 地址，对其赋值时用于地址的跳转</h3><ol><li>href 属性获取完整的 URL 地址，对其赋值时用于地址的跳转</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 1. location.href 得到url地址 可读写 可利用js跳转页面</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(location.<span class="property">href</span>)</span><br><span class="line"><span class="comment">// location.href = &#x27;http://baidu.com&#x27;</span></span><br></pre></td></tr></table></figure><h5 id="5秒钟之后跳转的页面"><a href="#5秒钟之后跳转的页面" class="headerlink" title="5秒钟之后跳转的页面"></a>5秒钟之后跳转的页面</h5><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 2. 3秒后跳转页面</span></span><br><span class="line">&lt;a href=<span class="string">&quot;&quot;</span>&gt;<span class="number">3</span>秒后跳转百度页面&lt;/a&gt;</span><br><span class="line"><span class="keyword">let</span> num1 = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;a&#x27;</span>)</span><br><span class="line"><span class="keyword">let</span> num2 = <span class="number">100</span></span><br><span class="line"><span class="keyword">let</span> num3 = <span class="built_in">setInterval</span>(<span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">    num2--</span><br><span class="line">    num1.<span class="property">innerHTML</span> = <span class="string">`<span class="subst">$&#123;num2&#125;</span>秒后跳转百度页面`</span></span><br><span class="line">    <span class="keyword">if</span> (num2 == <span class="number">1</span>) &#123;</span><br><span class="line">        <span class="built_in">clearInterval</span>(num3)</span><br><span class="line">        location.<span class="property">href</span> = <span class="string">&#x27;http://baidu.com&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;, <span class="number">1000</span>)</span><br></pre></td></tr></table></figure><h3 id="2-search-属性获取地址中携带的参数，符号-？后面部分"><a href="#2-search-属性获取地址中携带的参数，符号-？后面部分" class="headerlink" title="2. search 属性获取地址中携带的参数，符号 ？后面部分"></a>2. search 属性获取地址中携带的参数，符号 ？后面部分</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- <span class="number">3.</span>location.<span class="property">search</span> 属性 --&gt;</span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">form</span> <span class="attr">action</span>=<span class="string">&quot;4.JS执行机制.html&quot;</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">    <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">name</span>=<span class="string">&quot;username&quot;</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">    <span class="tag">&lt;<span class="name">button</span>&gt;</span>提交<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span></span><br><span class="line"><span class="language-xml"><span class="tag">&lt;/<span class="name">form</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">// 3. location.search 属性 ?username=abd</span></span><br><span class="line"><span class="language-xml">document.write(location.search)</span></span><br></pre></td></tr></table></figure><h3 id="3-hash-属性获取地址中的啥希值，符号-后面部分"><a href="#3-hash-属性获取地址中的啥希值，符号-后面部分" class="headerlink" title="3. hash 属性获取地址中的啥希值，符号 # 后面部分"></a>3. hash 属性获取地址中的啥希值，符号 # 后面部分</h3><blockquote><p>后期vue路由的铺垫，经常用于不刷新页面，显示不同页面，比如 网易云音乐</p></blockquote><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 4. location.hash # 属性 vue路由</span></span><br><span class="line">&lt;a href=<span class="string">&quot;#one&quot;</span>&gt;第一个&lt;/a&gt;</span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">&quot;#two&quot;</span>&gt;</span>第二个<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span></span><br><span class="line"><span class="keyword">let</span> num4 = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;a&#x27;</span>)</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(location.<span class="property">hash</span>)</span><br></pre></td></tr></table></figure><h3 id="4-reload-方法用来刷新当前页面，传入参数-true-时表示强制刷新"><a href="#4-reload-方法用来刷新当前页面，传入参数-true-时表示强制刷新" class="headerlink" title="4. reload 方法用来刷新当前页面，传入参数 true 时表示强制刷新"></a>4. reload 方法用来刷新当前页面，传入参数 true 时表示强制刷新</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 5. location.reload 属性 方法</span></span><br><span class="line">button <span class="keyword">class</span>=<span class="string">&quot;btn&quot;</span>&gt;强制刷新&lt;/button&gt;</span><br><span class="line"><span class="keyword">let</span> num5 = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.btn&#x27;</span>)</span><br><span class="line">num5.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">    <span class="comment">// 强制刷新 默认为 true</span></span><br><span class="line">    location.<span class="title function_">reload</span>()</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure><h3 id="3-navigator对象"><a href="#3-navigator对象" class="headerlink" title="3. navigator对象"></a>3. navigator对象</h3><ol><li>navigator的数据类型是对象，该对象下记录了浏览器自身的相关信息</li><li>通过 userAgent 检测浏览器的版本及平台</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(navigator)</span><br><span class="line"><span class="comment">// 1.检测 userAgent 浏览器信息</span></span><br><span class="line">!(<span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">    <span class="keyword">const</span> userAgent = navigator.<span class="property">userAgent</span></span><br><span class="line"><span class="comment">// 2.验证是否为Android或iPhone</span></span><br><span class="line">    <span class="keyword">const</span> android = userAgent.<span class="title function_">match</span>(<span class="regexp">/(Android);?[\s\/]+([\d.]+)?/</span>)</span><br><span class="line">    <span class="keyword">const</span> iphone = userAgent.<span class="title function_">match</span>(<span class="regexp">/(iPhone\sOS)\s([\d_]+)/</span>)</span><br><span class="line"><span class="comment">// 3.如果是Android或iPhone，则跳转至移动站点</span></span><br><span class="line">    <span class="keyword">if</span> (android || iphone) &#123;</span><br><span class="line">        location.<span class="property">href</span> = <span class="string">&#x27;http://baidu.com&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;)()</span><br></pre></td></tr></table></figure><h3 id="4-histroy对象"><a href="#4-histroy对象" class="headerlink" title="4. histroy对象"></a>4. histroy对象</h3><ol><li>history 的数据类型是对象，该对象与浏览器地址栏的操作相对应，如前进、后退、历史记录等</li><li>history 对象一般在实际开发中比较少用，但是会在一些 OA 办公系统中见到</li></ol><table><thead><tr><th align="left">使用方法</th><th align="left">作用</th></tr></thead><tbody><tr><td align="left">back()</td><td align="left">可以后退</td></tr><tr><td align="left">forward()</td><td align="left">前进</td></tr><tr><td align="left">go(参数)</td><td align="left">前进后退, 1是前进页面, -1是后退页面</td></tr></tbody></table><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">&lt;button&gt;前进&lt;/button&gt;</span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">button</span>&gt;</span>后退<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span></span><br><span class="line"><span class="comment">// 1. history.forward()</span></span><br><span class="line"><span class="keyword">let</span> btn = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;button:first-child&#x27;</span>)</span><br><span class="line">btn.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">    <span class="comment">// history.forward()</span></span><br><span class="line">    history.<span class="title function_">go</span>(<span class="number">1</span>)</span><br><span class="line">&#125;)</span><br><span class="line"><span class="comment">// 2. history.back()</span></span><br><span class="line"><span class="keyword">let</span> btn1 = btn.<span class="property">nextElementSibling</span></span><br><span class="line">btn1.<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">    <span class="comment">// history.back()</span></span><br><span class="line">    history.<span class="title function_">go</span>(-<span class="number">1</span>)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure><h2 id="4-本地存储"><a href="#4-本地存储" class="headerlink" title="4. 本地存储"></a>4. 本地存储</h2><ol><li>随着互联网的快速发展，基于网页的应用越来越普遍，同时也变的越来越复杂，为了满足各种各样的需求，会经常性在 本地存储大量的数据，HTML5规范提出了相关解决方案</li><li>数据存储在用户浏览器中</li><li>设置、读取方便、甚至页面刷新不丢失数据</li><li>容量较大，sessionStorage和localStorage约 5M 左右</li></ol><h3 id="1-localStorage"><a href="#1-localStorage" class="headerlink" title="1. localStorage"></a>1. localStorage</h3><ol><li>生命周期永久生效，除非手动删除 否则关闭页面也会存在</li><li>可以多窗口 (页面) 共享 (同一浏览器可以共享)</li><li>以键值对的形式存储使用</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 1. 存储数据 localStorage.setItem(&#x27;键&#x27;, &#x27;值&#x27;)</span></span><br><span class="line"><span class="variable language_">localStorage</span>.<span class="title function_">setItem</span>(<span class="string">&#x27;name&#x27;</span>, <span class="string">&#x27;csy&#x27;</span>)</span><br><span class="line"><span class="comment">// 2. 获取数据 getItem(&#x27;键&#x27;)</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="variable language_">localStorage</span>.<span class="title function_">getItem</span>(<span class="string">&#x27;name&#x27;</span>))</span><br><span class="line"><span class="comment">// 3. 删除数据 removeItem(&#x27;值&#x27;)</span></span><br><span class="line"><span class="variable language_">localStorage</span>.<span class="title function_">removeItem</span>(<span class="string">&#x27;name&#x27;</span>)</span><br></pre></td></tr></table></figure><h3 id="2-存储复杂数据类型存储"><a href="#2-存储复杂数据类型存储" class="headerlink" title="2. 存储复杂数据类型存储"></a>2. 存储复杂数据类型存储</h3><p>本地只能存储字符串,无法存储复杂数据类型.需要将复杂数据类型转换成JSON字符串,在存储到本地</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 存储复杂数据类型 引用数据类型</span></span><br><span class="line"><span class="keyword">let</span> obj = &#123;</span><br><span class="line">    <span class="attr">uanme</span>: <span class="string">&#x27;小城&#x27;</span>,</span><br><span class="line">    <span class="attr">age</span>: <span class="number">18</span>,</span><br><span class="line">    <span class="attr">sex</span>: <span class="string">&#x27;男&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// JSON 格式 属性和值 双引号包含</span></span><br><span class="line"><span class="keyword">let</span> obj1 = &#123;</span><br><span class="line">    <span class="string">&quot;uanme&quot;</span>: <span class="string">&quot;小城&quot;</span>,</span><br><span class="line">    <span class="string">&quot;age&quot;</span>: <span class="string">&quot;18&quot;</span>,</span><br><span class="line">    <span class="string">&quot;sex&quot;</span>: <span class="string">&quot;男&quot;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="number">1.</span> <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(复杂数据类型)</span><br><span class="line"><span class="number">2.</span> 将复杂数据转换成<span class="title class_">JSON</span>字符串 存储 本地存储中</span><br><span class="line"><span class="number">3.</span> <span class="variable language_">localStorage</span>.<span class="title function_">setItem</span>(<span class="string">&#x27;obj&#x27;</span>, obj) 是对象 但不知道什么名</span><br><span class="line"><span class="number">4.</span> 复杂数据类型转换为 json字符串 进行存储</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="variable language_">localStorage</span>.<span class="title function_">getItem</span>(<span class="string">&#x27;obj&#x27;</span>, <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(obj)))</span><br><span class="line"><span class="variable language_">localStorage</span>.<span class="title function_">setItem</span>(<span class="string">&#x27;obj&#x27;</span>, <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(obj))</span><br><span class="line"></span><br><span class="line"><span class="number">1.</span> <span class="title class_">JSON</span>.<span class="title function_">parse</span>(<span class="title class_">JSON</span>字符串)</span><br><span class="line"><span class="number">2.</span> 将<span class="title class_">JSON</span>字符串转换成对象 取出 时候使用</span><br><span class="line"><span class="number">3.</span> 取数据 将 json字符串 转换为 对象</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">JSON</span>.<span class="title function_">parse</span>(<span class="variable language_">localStorage</span>.<span class="title function_">getItem</span>(<span class="string">&#x27;obj&#x27;</span>)))</span><br></pre></td></tr></table></figure><h3 id="3-sessionStorage（了解）"><a href="#3-sessionStorage（了解）" class="headerlink" title="3. sessionStorage（了解）"></a>3. sessionStorage（了解）</h3><ol><li>生命周期为关闭浏览器窗口</li><li>在同一个窗口(页面)下数据可以共享</li><li>以键值对的形式存储使用</li><li>用法跟localStorage 基本相同</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 生命周期为关闭浏览器窗口 (了解)</span></span><br><span class="line">sessionStorage.<span class="title function_">setItem</span>(<span class="string">&#x27;uname&#x27;</span>, <span class="string">&#x27;csy&#x27;</span>)</span><br></pre></td></tr></table></figure><h2 id="5-自定义属性"><a href="#5-自定义属性" class="headerlink" title="5. 自定义属性"></a>5. 自定义属性</h2><ol><li>固有属性: 标签天生自带的属性 比如class id title等, 可以直接使用点语法操作</li><li>由程序员自己添加的属性,在DOM对象中找不到, 无法使用点语法操作,必须使用专门的API</li></ol><ul><li>getAttribute(‘属性名’) &#x2F;&#x2F; 获取自定义属性</li><li>setAttribute(‘属性名’, ‘属性值’) &#x2F;&#x2F; 设置自定义属性</li><li>removeAttribute(‘属性名’) &#x2F;&#x2F; 删除自定义属性</li></ul><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 自带的属性id: 直接用点语法操作</span></span><br><span class="line"><span class="comment">// 由程序员自己添加属性 在DOM对象中找不到 无法使用点语法操作 须使用专门API</span></span><br><span class="line">&lt;div <span class="keyword">class</span>=<span class="string">&quot;box&quot;</span> data-id=<span class="string">&quot;1&quot;</span> data-id1=<span class="string">&quot;2&quot;</span>&gt;&lt;/div&gt;</span><br><span class="line"><span class="keyword">let</span> num1 = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.box&#x27;</span>)</span><br><span class="line"><span class="comment">// 1. 设置自定义属性</span></span><br><span class="line">num1.<span class="title function_">setAttribute</span>(<span class="string">&#x27;myid&#x27;</span>, <span class="number">10</span>)</span><br><span class="line"><span class="comment">// 2. 获取自定义属性</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(num1.<span class="title function_">getAttribute</span>(<span class="string">&#x27;myid&#x27;</span>))</span><br><span class="line"><span class="comment">// 3. 删除自定义属性</span></span><br><span class="line">num1.<span class="title function_">removeAttribute</span>(<span class="string">&#x27;myid&#x27;</span>)</span><br></pre></td></tr></table></figure><h3 id="data-自定义属性"><a href="#data-自定义属性" class="headerlink" title="data-自定义属性:"></a>data-自定义属性:</h3><ol><li>传统的自定义属性没有专门的定义规则,开发者随意定值,不够规范,所以在html5中推出来了专门的data-自定义属性 在 标签上一律以data-开头</li><li>在DOM对象上一律以dataset对象方式获取</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// dataset对象 不能随意定值 需data-id规范 取值是数组</span></span><br><span class="line">&lt;div <span class="keyword">class</span>=<span class="string">&quot;box&quot;</span> data-id=<span class="string">&quot;1&quot;</span> data-id1=<span class="string">&quot;2&quot;</span>&gt;&lt;/div&gt;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(num1.<span class="property">dataset</span>.<span class="property">id</span>)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(num1.<span class="property">dataset</span>)</span><br></pre></td></tr></table></figure><h2 id="5-swiper-插件"><a href="#5-swiper-插件" class="headerlink" title="5. swiper 插件"></a>5. swiper 插件</h2><ol><li>插件: 就是别人写好的一些代码,我们只需要复制对应的代码,就可以直接实现对应的效果</li><li>熟悉官网,了解这个插件可以完成什么需求 <a target="_blank" rel="noopener" href="https://www.swiper.com.cn/">https://www.swiper.com.cn</a></li><li>看在线演示,找到符合自己需求的demo <a target="_blank" rel="noopener" href="https://www.swiper.com.cn/demo/index.html">https://www.swiper.com.cn/demo/index.html</a></li><li>查看基本使用流程 <a target="_blank" rel="noopener" href="https://www.swiper.com.cn/usage/index.html">https://www.swiper.com.cn/usage/index.html</a></li><li>查看APi文档,去配置自己的插件 <a target="_blank" rel="noopener" href="https://www.swiper.com.cn/api/index.html">https://www.swiper.com.cn/api/index.html</a></li><li>注意: 多个swiper同时使用的时候, 类名需要注意区分</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> swiper = <span class="keyword">new</span> <span class="title class_">Swiper</span>(<span class="string">&quot;.Swiper&quot;</span>, &#123;</span><br><span class="line">    <span class="attr">slidesPerView</span>: <span class="number">1</span>, <span class="comment">// 等分播放</span></span><br><span class="line">    <span class="attr">spaceBetween</span>: <span class="number">0</span>, <span class="comment">// 背景过渡</span></span><br><span class="line">    <span class="attr">loop</span>: <span class="literal">true</span>, <span class="comment">// 是否循环</span></span><br><span class="line">    <span class="attr">pagination</span>: &#123; <span class="comment">// 小圆点显示/隐藏</span></span><br><span class="line">        <span class="attr">el</span>: <span class="string">&quot;.swiper-pagination&quot;</span>,</span><br><span class="line">        <span class="attr">clickable</span>: <span class="literal">true</span>, <span class="comment">// 小圆点是否能点</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="attr">navigation</span>: &#123; <span class="comment">// 左右按钮</span></span><br><span class="line">        <span class="attr">nextEl</span>: <span class="string">&quot;.swiper-button-next&quot;</span>,</span><br><span class="line">        <span class="attr">prevEl</span>: <span class="string">&quot;.swiper-button-prev&quot;</span>,</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="attr">autoplay</span>: &#123; <span class="comment">// 自动切换</span></span><br><span class="line">        <span class="attr">delay</span>: <span class="number">400</span>, <span class="comment">// 间隔时间</span></span><br><span class="line">        <span class="attr">stopOnLastSlide</span>: <span class="literal">false</span>, <span class="comment">// 到最后一个停止切换 loop模式下无效</span></span><br><span class="line">        <span class="attr">disableOnInteraction</span>: <span class="literal">false</span>, <span class="comment">// 拖动/点击后 停止自动切换</span></span><br><span class="line">    &#125;,</span><br><span class="line">    keyboard : <span class="literal">true</span>, <span class="comment">// 键盘左右键控制</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure><h2 id="6-综合案例"><a href="#6-综合案例" class="headerlink" title="6. 综合案例"></a>6. 综合案例</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br></pre></td><td class="code"><pre><span class="line">需求①：读取本地存储数据（封装函数）</span><br><span class="line">如果本地存储有数据，则返回 <span class="title class_">JSON</span>.<span class="title function_">parse</span>() 之后的对象</span><br><span class="line">如果本地存储没有数据，则默认写入三条数据，注意存储的利用<span class="title class_">JSON</span>.<span class="title function_">stringify</span>() 存 储<span class="title class_">JSON</span> 格式的数据</span><br><span class="line">需求②：渲染模块</span><br><span class="line">先读取本地存储数据，然后渲染</span><br><span class="line">需求③：添加模块</span><br><span class="line">注意，先取的最新的本地存储数据，然后追加</span><br><span class="line">新增了数据，要把新数据存储到本地存储别，忘记转换</span><br><span class="line">需求④：删除模块</span><br><span class="line">注意，先取的最新的本地存储数据，然后追加</span><br><span class="line">新增了数据，要把新数据存储到本地存储别忘记转换</span><br><span class="line">&lt;body&gt;</span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">h1</span>&gt;</span>新增学员<span class="tag">&lt;/<span class="name">h1</span>&gt;</span></span></span><br><span class="line">&lt;div class=&quot;info&quot;&gt;</span><br><span class="line">  姓名：&lt;input type=&quot;text&quot; class=&quot;uname&quot;&gt;</span><br><span class="line">  年龄：&lt;input type=&quot;text&quot; class=&quot;age&quot;&gt;</span><br><span class="line">  性别: &lt;select name=&quot;gender&quot; id=&quot;&quot; class=&quot;gender&quot;&gt;</span><br><span class="line">    &lt;option value=&quot;男&quot;&gt;男&lt;/option&gt;</span><br><span class="line">    &lt;option value=&quot;女&quot;&gt;女&lt;/option&gt;</span><br><span class="line">  &lt;/select&gt;</span><br><span class="line">  薪资：&lt;input type=&quot;text&quot; class=&quot;salary&quot;&gt;</span><br><span class="line">  就业城市：&lt;select name=&quot;city&quot; id=&quot;&quot; class=&quot;city&quot;&gt;</span><br><span class="line">    &lt;option value=&quot;北京&quot;&gt;北京&lt;/option&gt;</span><br><span class="line">    &lt;option value=&quot;上海&quot;&gt;上海&lt;/option&gt;</span><br><span class="line">    &lt;option value=&quot;广州&quot;&gt;广州&lt;/option&gt;</span><br><span class="line">    &lt;option value=&quot;深圳&quot;&gt;深圳&lt;/option&gt;</span><br><span class="line">    &lt;option value=&quot;曹县&quot;&gt;曹县&lt;/option&gt;</span><br><span class="line">  &lt;/select&gt;</span><br><span class="line">  &lt;button class=&quot;add&quot;&gt;录入&lt;/button&gt;</span><br><span class="line">&lt;/div&gt;</span><br><span class="line">&lt;h1&gt;就业榜&lt;/h1&gt;</span><br><span class="line">&lt;table&gt;</span><br><span class="line">  &lt;thead&gt;</span><br><span class="line">    &lt;tr&gt;</span><br><span class="line">      &lt;th&gt;学号&lt;/th&gt;</span><br><span class="line">      &lt;th&gt;姓名&lt;/th&gt;</span><br><span class="line">      &lt;th&gt;年龄&lt;/th&gt;</span><br><span class="line">      &lt;th&gt;性别&lt;/th&gt;</span><br><span class="line">      &lt;th&gt;薪资&lt;/th&gt;</span><br><span class="line">      &lt;th&gt;就业城市&lt;/th&gt;</span><br><span class="line">      &lt;th&gt;操作&lt;/th&gt;</span><br><span class="line">    &lt;/tr&gt;</span><br><span class="line">  &lt;/thead&gt;</span><br><span class="line">  &lt;tbody&gt;</span><br><span class="line">  &lt;/tbody&gt;</span><br><span class="line">&lt;/table&gt;</span><br><span class="line">&lt;script&gt;</span><br><span class="line">  // 1. 读取本地存储数据 封装函数 </span><br><span class="line">  function fn1() &#123;</span><br><span class="line">    let num1 = localStorage.getItem(&#x27;data&#x27;)</span><br><span class="line">    if (num1) &#123;</span><br><span class="line">      // 如果本地存储有数据 则返回 JSON.parse 对象</span><br><span class="line">      return JSON.parse(num1)</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">      // 如果没有则默认写入三条数据 利用stringify 存储</span><br><span class="line">    let arr = [</span><br><span class="line">      &#123; stuid: 1001, uname: &#x27;欧阳霸天&#x27;, age: 19, gender: &#x27;男&#x27;, salary: &#x27;20000&#x27;, city: &#x27;上海&#x27; &#125;,</span><br><span class="line">      &#123; stuid: 1002, uname: &#x27;令狐霸天&#x27;, age: 29, gender: &#x27;男&#x27;, salary: &#x27;30000&#x27;, city: &#x27;北京&#x27; &#125;,</span><br><span class="line">      &#123; stuid: 1003, uname: &#x27;诸葛霸天&#x27;, age: 39, gender: &#x27;男&#x27;, salary: &#x27;2000&#x27;, city: &#x27;北京&#x27; &#125;,</span><br><span class="line">    ]</span><br><span class="line">      localStorage.setItem(&#x27;data&#x27;, JSON.stringify(arr))</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  fn1()</span><br><span class="line"></span><br><span class="line">  let tbody = document.querySelector(&#x27;tbody&#x27;)</span><br><span class="line">  let btn = document.querySelector(&#x27;.add&#x27;)</span><br><span class="line">  let uname = document.querySelector(&#x27;.uname&#x27;)</span><br><span class="line">  let age = document.querySelector(&#x27;.age&#x27;)</span><br><span class="line">  let gender = document.querySelector(&#x27;.gender&#x27;)</span><br><span class="line">  let salary = document.querySelector(&#x27;.salary&#x27;)</span><br><span class="line">  let city = document.querySelector(&#x27;.city&#x27;)</span><br><span class="line">  function fn() &#123;</span><br><span class="line">  // 2. 先读取本地存储数据 再渲染</span><br><span class="line">    let arr = fn1()</span><br><span class="line">    tbody.innerHTML = &#x27;&#x27;</span><br><span class="line">    for (let num1 = 0; num1 &lt; arr.length; num1++) &#123;</span><br><span class="line">      let tr = document.createElement(&#x27;tr&#x27;)</span><br><span class="line">      tr.innerHTML = `</span><br><span class="line">          &lt;tr&gt;</span><br><span class="line">            &lt;td&gt;$&#123;arr[num1].stuid&#125;&lt;/td&gt;</span><br><span class="line">            &lt;td&gt;$&#123;arr[num1].uname&#125;&lt;/td&gt;</span><br><span class="line">            &lt;td&gt;$&#123;arr[num1].age&#125;&lt;/td&gt;</span><br><span class="line">            &lt;td&gt;$&#123;arr[num1].gender&#125;&lt;/td&gt;</span><br><span class="line">            &lt;td&gt;$&#123;arr[num1].salary&#125;&lt;/td&gt;</span><br><span class="line">            &lt;td&gt;$&#123;arr[num1].city&#125;&lt;/td&gt;</span><br><span class="line">            &lt;td&gt;&lt;a href=&quot;javascript:&quot; id=&quot;$&#123;num1&#125;&quot;&gt;删除&lt;/a&gt;&lt;/td&gt;</span><br><span class="line">          &lt;/tr&gt;`</span><br><span class="line">      tbody.appendChild(tr)</span><br><span class="line">      uname.value = age.value = salary.value = &#x27;&#x27;</span><br><span class="line">      gender.value = &#x27;男&#x27;</span><br><span class="line">      city.value = &#x27;北京&#x27;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  fn()</span><br><span class="line"></span><br><span class="line">  btn.addEventListener(&#x27;click&#x27;, function () &#123;</span><br><span class="line">    // 3. 先读取本地存储数据 再渲染</span><br><span class="line">    let arr = fn1()</span><br><span class="line">    arr.push(&#123;</span><br><span class="line">      stuid: arr[arr.length - 1].stuid + 1, </span><br><span class="line">      uname: uname.value, </span><br><span class="line">      age: age.value, </span><br><span class="line">      gender: gender.value, </span><br><span class="line">      salary: salary.value, </span><br><span class="line">      city: city.value</span><br><span class="line">    &#125;)</span><br><span class="line">    // 4. 存储到本地</span><br><span class="line">    localStorage.setItem(&#x27;data&#x27;, JSON.stringify(arr))</span><br><span class="line">    fn()</span><br><span class="line">  &#125;)</span><br><span class="line"></span><br><span class="line">  tbody.addEventListener(&#x27;click&#x27;, function (e) &#123;</span><br><span class="line">    // 5. 先读取本地数据 再渲染</span><br><span class="line">    let arr = fn1()</span><br><span class="line">    if (e.target.tagName == &#x27;A&#x27;) &#123;</span><br><span class="line">      // 7. 第一条数据不能删除 添加判断</span><br><span class="line">      if (e.target.id == 0) &#123;</span><br><span class="line">        return alert(&#x27;此条数据不能被删除&#x27;)</span><br><span class="line">      &#125;</span><br><span class="line">      arr.splice(e.target.id, 1)</span><br><span class="line">      // 6. 存储到本地</span><br><span class="line">      localStorage.setItem(&#x27;data&#x27;, JSON.stringify(arr))</span><br><span class="line">    &#125;</span><br><span class="line">    fn()</span><br><span class="line">  &#125;)</span><br><span class="line">&lt;/script&gt;</span><br><span class="line">&lt;/body&gt;</span><br></pre></td></tr></table></figure><hr><h4 id="本节单词"><a href="#本节单词" class="headerlink" title="本节单词:"></a>本节单词:</h4><ol><li><p>localStorage</p></li><li><p>setItem</p></li><li><p>getItem</p></li><li><p>stringify</p></li><li><p>parse</p></li><li><p>removeItem</p></li><li><p>setTimeout</p></li><li><p>location</p></li><li><p>href</p></li><li><p>search</p></li><li><p>hash</p></li><li><p>reload</p></li><li><p>setAttribute</p></li><li><p>getAttribute</p></li><li><p>removeAttribute</p></li><li><p>dataset</p></li><li><p>histroy</p></li><li><p>forward</p></li><li><p>back</p></li><li><p>go</p></li><li><p>json</p></li><li><p>window</p></li><li><p>navigator</p></li><li><p>sessionStorage</p></li><li><p>Browser Object Model</p></li></ol></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">本文作者:</span> <span class="post-copyright-info"><a href="https://webxc.eu.org">XC's Blog</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">本文链接:</span> <span class="post-copyright-info"><a href="https://webxc.eu.org/post/fr67/">https://webxc.eu.org/post/fr67/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明:</span> <span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://webxc.eu.org" target="_blank">XC's Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Web-APIs%E7%AC%94%E8%AE%B0/">Web APIs笔记</a></div><div class="post_share"><div class="social-share" data-image="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/webapis.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://npm.elemecdn.com/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload='this.media="all"'><script src="https://npm.elemecdn.com/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://npm.elemecdn.com/webxc@1.0.0/lxfs/wechat.png" target="_blank"><img class="post-qr-code-img" src="https://npm.elemecdn.com/webxc@1.0.0/lxfs/wechat.png" alt="Wechat"></a><div class="post-qr-code-desc">Wechat</div></li><li class="reward-item"><a href="https://npm.elemecdn.com/webxc@1.0.0/lxfs/alipay.jpg" target="_blank"><img class="post-qr-code-img" src="https://npm.elemecdn.com/webxc@1.0.0/lxfs/alipay.jpg" alt="Alipay"></a><div class="post-qr-code-desc">Alipay</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/post/32dr/"><img class="prev-cover" src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/webapis.jpg" onerror='onerror=null,src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇文章</div><div class="prev_info">Web APIs第五天</div></div></a></div><div class="next-post pull-right"><a href="/post/ar34/"><img class="next-cover" src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/webapis.jpg" onerror='onerror=null,src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="cover of next post"><div class="pagination-info"><div class="label">下一篇文章</div><div class="next_info">Web APIs第七天</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/post/fa31/" title="ES6模块化与异步编程"><img class="cover" src="https://npm.elemecdn.com/webxc/cover/js1.webp" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">ES6模块化与异步编程</div></div></a></div><div><a href="/post/ce68/" title="Web APIs第一天"><img class="cover" src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/webapis.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-15</div><div class="title">Web APIs第一天</div></div></a></div><div><a href="/post/ar34/" title="Web APIs第七天"><img class="cover" src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/webapis.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-04-17</div><div class="title">Web APIs第七天</div></div></a></div></div></div><hr><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i> <span>评论</span></div></div><div class="comment-wrap"><div><div id="twikoo-wrap"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="avatar"></div><div class="author-info__name">XC's Blog</div><div class="author-info__description">XC's Blog 记录生活和学习文章</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">95</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">25</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><div class="card-info-social-icons is-center"><a class="social-icon" href="https://tenapi.cn/qqzlk/?qq=2848141597" target="_blank" title="QQ"><i class="iconfont icon-QQ"></i></a><a class="social-icon" href="https://npm.elemecdn.com/webxc@1.0.0/lxfs/wechat.jpg" target="_blank" title="微信"><i class="iconfont icon-weixin"></i></a><a class="social-icon" href="https://github.com/web-xc" target="_blank" title="Github"><i class="iconfont icon-github"></i></a><a class="social-icon" href="https://space.bilibili.com/2134826455" target="_blank" title="BiliBili"><i class="iconfont icon-bilibili"></i></a><a class="social-icon" href="https://music.163.com/#/user/home?id=323682437" target="_blank" title="网易云音乐"><i class="iconfont icon-wyy"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">原网站因使用.ml域名被回收, 再加上本人因学习原因, 没怎么打理博客, 使用了https://webxc.eu.org域名来维持博客运行, 如果有加友联的朋友们, 去友联页看信息即可, 如果原来有加过的, 麻烦在原来域名后缀改一下(.ml ==> .eu.org)就行, 博客写的太乱了, 没时间打理, 兄弟们谅解😁😁~~</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#BOM-%E6%93%8D%E4%BD%9C%E6%B5%8F%E8%A7%88%E5%99%A8"><span class="toc-number">1.</span> <span class="toc-text">BOM- 操作浏览器</span></a></li></ol><li class="toc-item toc-level-2"><a class="toc-link" href="#1-JS%E6%89%A7%E8%A1%8C%E6%9C%BA%E5%88%B6"><span class="toc-number"></span> <span class="toc-text">1. JS执行机制</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E5%90%8C%E6%AD%A5"><span class="toc-number">1.</span> <span class="toc-text">1. 同步</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E5%BC%82%E6%AD%A5"><span class="toc-number">2.</span> <span class="toc-text">2. 异步</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E4%B8%80%E8%88%AC%E8%80%8C%E8%A8%80%EF%BC%8C%E5%BC%82%E6%AD%A5%E4%BB%BB%E5%8A%A1%E6%9C%89%E4%BB%A5%E4%B8%8B%E4%B8%89%E7%A7%8D%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.0.1.</span> <span class="toc-text">一般而言，异步任务有以下三种类型:</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-JS%E6%89%A7%E8%A1%8C%E8%BF%87%E7%A8%8B"><span class="toc-number"></span> <span class="toc-text">2. JS执行过程</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-Window%E5%AF%B9%E8%B1%A1"><span class="toc-number"></span> <span class="toc-text">3. Window对象</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E5%AE%9A%E6%97%B6%E5%99%A8-%E5%BB%B6%E6%97%B6%E5%87%BD%E6%95%B0"><span class="toc-number">1.</span> <span class="toc-text">1. 定时器-延时函数</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-%E4%B8%A4%E7%A7%8D%E5%AE%9A%E6%97%B6%E5%99%A8%E5%AF%B9%E6%AF%94"><span class="toc-number">1.0.1.</span> <span class="toc-text">1. 两种定时器对比:</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-5%E7%A7%92%E9%92%9F%E4%B9%8B%E5%90%8E%E6%B6%88%E5%A4%B1%E7%9A%84%E5%B9%BF%E5%91%8A"><span class="toc-number">1.0.2.</span> <span class="toc-text">2. 5秒钟之后消失的广告</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-location%E5%AF%B9%E8%B1%A1"><span class="toc-number">2.</span> <span class="toc-text">2. location对象</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-href-%E5%B1%9E%E6%80%A7%E8%8E%B7%E5%8F%96%E5%AE%8C%E6%95%B4%E7%9A%84-URL-%E5%9C%B0%E5%9D%80%EF%BC%8C%E5%AF%B9%E5%85%B6%E8%B5%8B%E5%80%BC%E6%97%B6%E7%94%A8%E4%BA%8E%E5%9C%B0%E5%9D%80%E7%9A%84%E8%B7%B3%E8%BD%AC"><span class="toc-number">3.</span> <span class="toc-text">1. href 属性获取完整的 URL 地址，对其赋值时用于地址的跳转</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#5%E7%A7%92%E9%92%9F%E4%B9%8B%E5%90%8E%E8%B7%B3%E8%BD%AC%E7%9A%84%E9%A1%B5%E9%9D%A2"><span class="toc-number">3.0.1.</span> <span class="toc-text">5秒钟之后跳转的页面</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-search-%E5%B1%9E%E6%80%A7%E8%8E%B7%E5%8F%96%E5%9C%B0%E5%9D%80%E4%B8%AD%E6%90%BA%E5%B8%A6%E7%9A%84%E5%8F%82%E6%95%B0%EF%BC%8C%E7%AC%A6%E5%8F%B7-%EF%BC%9F%E5%90%8E%E9%9D%A2%E9%83%A8%E5%88%86"><span class="toc-number">4.</span> <span class="toc-text">2. search 属性获取地址中携带的参数，符号 ？后面部分</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-hash-%E5%B1%9E%E6%80%A7%E8%8E%B7%E5%8F%96%E5%9C%B0%E5%9D%80%E4%B8%AD%E7%9A%84%E5%95%A5%E5%B8%8C%E5%80%BC%EF%BC%8C%E7%AC%A6%E5%8F%B7-%E5%90%8E%E9%9D%A2%E9%83%A8%E5%88%86"><span class="toc-number">5.</span> <span class="toc-text">3. hash 属性获取地址中的啥希值，符号 # 后面部分</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-reload-%E6%96%B9%E6%B3%95%E7%94%A8%E6%9D%A5%E5%88%B7%E6%96%B0%E5%BD%93%E5%89%8D%E9%A1%B5%E9%9D%A2%EF%BC%8C%E4%BC%A0%E5%85%A5%E5%8F%82%E6%95%B0-true-%E6%97%B6%E8%A1%A8%E7%A4%BA%E5%BC%BA%E5%88%B6%E5%88%B7%E6%96%B0"><span class="toc-number">6.</span> <span class="toc-text">4. reload 方法用来刷新当前页面，传入参数 true 时表示强制刷新</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-navigator%E5%AF%B9%E8%B1%A1"><span class="toc-number">7.</span> <span class="toc-text">3. navigator对象</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-histroy%E5%AF%B9%E8%B1%A1"><span class="toc-number">8.</span> <span class="toc-text">4. histroy对象</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-%E6%9C%AC%E5%9C%B0%E5%AD%98%E5%82%A8"><span class="toc-number"></span> <span class="toc-text">4. 本地存储</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-localStorage"><span class="toc-number">1.</span> <span class="toc-text">1. localStorage</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E5%AD%98%E5%82%A8%E5%A4%8D%E6%9D%82%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E5%AD%98%E5%82%A8"><span class="toc-number">2.</span> <span class="toc-text">2. 存储复杂数据类型存储</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-sessionStorage%EF%BC%88%E4%BA%86%E8%A7%A3%EF%BC%89"><span class="toc-number">3.</span> <span class="toc-text">3. sessionStorage（了解）</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B1%9E%E6%80%A7"><span class="toc-number"></span> <span class="toc-text">5. 自定义属性</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#data-%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B1%9E%E6%80%A7"><span class="toc-number">1.</span> <span class="toc-text">data-自定义属性:</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-swiper-%E6%8F%92%E4%BB%B6"><span class="toc-number"></span> <span class="toc-text">5. swiper 插件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-%E7%BB%BC%E5%90%88%E6%A1%88%E4%BE%8B"><span class="toc-number"></span> <span class="toc-text">6. 综合案例</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%9C%AC%E8%8A%82%E5%8D%95%E8%AF%8D"><span class="toc-number">0.1.</span> <span class="toc-text">本节单词:</span></a></li></ol></li></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/post/ds2s/" title="整个前端面试题"><img src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="整个前端面试题"></a><div class="content"><a class="title" href="/post/ds2s/" title="整个前端面试题">整个前端面试题</a><time datetime="2023-08-31T02:00:00.000Z" title="发表于 2023-08-31 02:00:00">2023-08-31</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/post/ds23/" title="常见前端面试题"><img src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="常见前端面试题"></a><div class="content"><a class="title" href="/post/ds23/" title="常见前端面试题">常见前端面试题</a><time datetime="2023-08-28T18:30:00.000Z" title="发表于 2023-08-28 18:30:00">2023-08-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/post/fe33/" title="硅谷甄选运营平台"><img src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="硅谷甄选运营平台"></a><div class="content"><a class="title" href="/post/fe33/" title="硅谷甄选运营平台">硅谷甄选运营平台</a><time datetime="2023-07-26T03:55:00.000Z" title="发表于 2023-07-26 03:55:00">2023-07-26</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2021 - 2023 By XC's Blog</div><div class="framework-info"><span></span> <a target="_blank" rel="noopener" href="https://icp.gov.moe/?keyword=20235221">萌ICP备20235221号</a><span class="footer-separator">|</span><span></span> <a target="_blank" rel="noopener" href="https://icp.gov.moe/">萌ICP查询</a><div id="running-time"></div></div><script>setInterval((()=>{let e=Math.round(new Date("2021-11-21 01:35:06").getTime()/1e3),t=Math.round(((new Date).getTime()+288e5)/1e3)-e,n=new Array(0,0,0,0,0);t>=31536e3&&(n[0]=parseInt(t/31536e3),t%=31536e3),t>=86400&&(n[1]=parseInt(t/86400),t%=86400),t>=3600&&(n[2]=parseInt(t/3600),t%=3600),t>=60&&(n[3]=parseInt(t/60),t%=60),t>0&&(n[4]=t),currentTimeHtml="本站已安全运行 "+n[0]+" 年 "+n[1]+" 天 "+n[2]+" 时 "+n[3]+" 分 "+n[4]+" 秒",document.getElementById("running-time").innerHTML=currentTimeHtml}),1e3)</script></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i><span id="percent">0<span>%</span></span></button><button id="go-down" type="button" title="直达底部" onclick="btf.scrollToDest(document.body.scrollHeight,500)"><i class="fas fa-arrow-down"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i> <span>正在载入文件,请稍后</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"></div></div><hr><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="https://npm.elemecdn.com/hexo-theme-butterfly/source/js/utils.js"></script><script src="https://npm.elemecdn.com/hexo-theme-butterfly@4.4.0/source/js/main.js"></script><script src="https://npm.elemecdn.com/@fancyapps/ui/dist/fancybox.umd.js"></script><script src="https://npm.elemecdn.com/instant.page/instantpage.js" type="module"></script><script src="https://npm.elemecdn.com/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://npm.elemecdn.com/node-snackbar/dist/snackbar.min.js"></script><script src="https://npm.elemecdn.com/hexo-theme-butterfly/source/js/search/local-search.js"></script><div class="js-pjax"><script>(()=>{const e=document.querySelectorAll("#article-container .mermaid-wrap");if(e.length){window.runMermaid=()=>{window.loadMermaid=!0;const t="dark"===document.documentElement.getAttribute("data-theme")?"dark":"default";Array.from(e).forEach(((e,n)=>{const d=e.firstElementChild,r="mermaid-"+n,m="%%{init:{ 'theme':'"+t+"'}}%%\n"+d.textContent;mermaid.mermaidAPI.render(r,m,(e=>{d.insertAdjacentHTML("afterend",e)}))}))};const t=()=>{window.loadMermaid?runMermaid():getScript("https://npm.elemecdn.com/mermaid/dist/mermaid.min.js").then(runMermaid)};window.pjax?t():document.addEventListener("DOMContentLoaded",t)}})()</script><script>(()=>{const o=()=>{twikoo.init(Object.assign({el:"#twikoo-wrap",envId:"https://blog2.webxc.eu.org/",region:"",onCommentLoaded:function(){btf.loadLightbox(document.querySelectorAll("#twikoo .tk-content img:not(.tk-owo-emotion)"))}},null))},t=()=>{"object"!=typeof twikoo?getScript("https://npm.elemecdn.com/twikoo@1.6.16/dist/twikoo.all.min.js").then(o):setTimeout(o,0)};t()})()</script></div><script data-pjax="false" defer src="https://npm.elemecdn.com/webxc@1.0.16/css/style.js"></script><script defer src="https://npm.elemecdn.com/hexo-theme-butterfly@4.4.0/source/js/search/local-search.js"></scrip><script src="https://npm.elemecdn.com/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful=!0,POWERMODE.shake=!0,POWERMODE.mobile=!0,document.body.addEventListener("input",POWERMODE)</script><script src="https://npm.elemecdn.com/pjax@0.2.8/pjax.min.js"></script><script>let pjaxSelectors=["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax",".tk-comments-container"];var pjax=new Pjax({elements:'a:not([target="_blank"])',selectors:pjaxSelectors,cacheBust:!1,analytics:!1,scrollRestoration:!1});document.addEventListener("pjax:send",(function(){if(window.tocScrollFn&&window.removeEventListener("scroll",window.tocScrollFn),window.scrollCollect&&window.removeEventListener("scroll",scrollCollect),"object"==typeof preloader&&preloader.initLoading(),document.getElementById("rightside").style.cssText="opacity: ''; transform: ''",window.aplayers)for(let e=0;e<window.aplayers.length;e++)window.aplayers[e].options.fixed||window.aplayers[e].destroy();"object"==typeof typed&&typed.destroy();const e=document.body.classList;e.contains("read-mode")&&e.remove("read-mode"),"object"==typeof disqusjs&&disqusjs.destroy()})),document.addEventListener("pjax:complete",(function(){window.refreshFn(),document.querySelectorAll("script[data-pjax]").forEach((e=>{const t=document.createElement("script"),o=e.text||e.textContent||e.innerHTML||"";Array.from(e.attributes).forEach((e=>t.setAttribute(e.name,e.value))),t.appendChild(document.createTextNode(o)),e.parentNode.replaceChild(t,e)})),GLOBAL_CONFIG.islazyload&&window.lazyLoadInstance.update(),"function"==typeof chatBtnFn&&chatBtnFn(),"function"==typeof panguInit&&panguInit(),"function"==typeof gtag&&gtag("config","",{page_path:window.location.pathname}),"object"==typeof _hmt&&_hmt.push(["_trackPageview",window.location.pathname]),"function"==typeof loadMeting&&document.getElementsByClassName("aplayer").length&&loadMeting(),"object"==typeof Prism&&Prism.highlightAll(),"object"==typeof preloader&&preloader.endLoading()})),document.addEventListener("pjax:error",(e=>{404===e.request.status&&pjax.loadUrl("/404.html")}))</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script data-pjax>function butterfly_swiper_injector_config(){var s=document.getElementById("recent-posts");console.log("已挂载butterfly_swiper"),s.insertAdjacentHTML("afterbegin",'<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms;"><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-08-31</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/ds2s/&quot;);" href="javascript:void(0);" alt="">整个前端面试题</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-08-28</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/ds23/&quot;);" href="javascript:void(0);" alt="">常见前端面试题</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-26</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fe33/&quot;);" href="javascript:void(0);" alt="">硅谷甄选运营平台</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-17</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/ew32/&quot;);" href="javascript:void(0);" alt="">Vue第三天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-16</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/aw92/&quot;);" href="javascript:void(0);" alt="">Vue第二天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-14</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/ou67/&quot;);" href="javascript:void(0);" alt="">Vue第一天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-05</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fn32/&quot;);" href="javascript:void(0);" alt="">Vue框架笔记</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-06-21</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fe11/&quot;);" href="javascript:void(0);" alt="">Vue前置JS功底</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/promise.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-06-11</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/pr67/&quot;);" href="javascript:void(0);" alt="">ES6-Promise语法与原理</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/ajax.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-06-08</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/or01/&quot;);" href="javascript:void(0);" alt="">Ajax第四天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/ajax.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-06-07</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fs67/&quot;);" href="javascript:void(0);" alt="">Ajax第三天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-05-11</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fe66/&quot;);" href="javascript:void(0);" alt="">JS进阶第四天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-05-10</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fe99/&quot;);" href="javascript:void(0);" alt="">JS进阶第三天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-05-05</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/us87/&quot;);" href="javascript:void(0);" alt="">JS进阶第二天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc@1.0.12/cover/cover15.jpg);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2022-10-31</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/2db5/&quot;);" href="javascript:void(0);" alt="">移动开发-Flex布局</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc@1.0.12/cover/cover16.jpg);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2022-11-14</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/1c7e/&quot;);" href="javascript:void(0);" alt="">移动开发-媒体查询</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc@1.0.12/cover/cover17.jpg);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2022-11-17</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/7fc/&quot;);" href="javascript:void(0);" alt="">移动开发-响应式</a><div class="blog-slider__text">点击查看</div></div></div></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div><div class="swiper-button-prev"></div><div class="swiper-button-next"></div></div></div>')}for(var elist="null".split(","),cpage=location.pathname,epage="all",flag=0,i=0;i<elist.length;i++)cpage.includes(elist[i])&&flag++;("all"===epage&&0==flag||epage===cpage)&&butterfly_swiper_injector_config()</script><script defer src="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiper.min.js"></script><script defer data-pjax src="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiper_init.js"></script></body></html>